Hello all,
Is there a way to use the ~/ path to link a CSS page?
I thought maybe something like this would work, but no go:
Is this possible to do with the link element?
Thanks
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 04:31:33 von NoSpamMgbworld
~ is filled in by a routine in WebControl (GetClientPath() I think. If not,
it is close). The link is not attached to a control. YOu can code your own
implementation of link that use the routine to covnert ~. Otherwise, you
cannot use ~ to represent route.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box!
|
*************************************************
"Lance Wynn" wrote in message
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
>
>
> Is this possible to do with the link element?
>
> Thanks
>
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 05:58:37 von jialge
Hello,
From your post, my understanding on this issue is: you wonder how to
resolve the root directory when we link to a style sheet. If I'm off base,
please feel free to let me know.
According to the MSDN article: ASP.NET Web Site Paths
http://msdn2.microsoft.com/en-us/library/ms178116.aspx
"ASP.NET includes the Web application root operator (~), which you can use
when specifying a path in *server controls*. ASP.NET resolves the ~
operator to the root of the current application. You can use the ~ operator
in conjunction with folders to specify a path that is based on the current
root."
Therefore, as Cowboy replied, the link is not attached to a server control,
and the operator '~' cannot be resolved as expected.
Here are two workarounds for your reference:
Workaround 1: Declare 'runat=server' for the
element, and use '~'
inside it. For instance,
Untitled Page
Workaround 2:
We can link to the style sheet with some server side codes
(quoted from
http://www.pluralsight.com/blogs/ted/archive/2005/08/31/1443 7.aspx)
public static void AddLinkedStyleSheet(Page page, string stylesheet)
{
HtmlLink link = new HtmlLink();
link.Href = page.ResolveUrl(stylesheet);
link1.Attributes["text"] = "text/css";
link1.Attributes["rel"] = "stylesheet";
Please let me know if you have any other concerns, or need anything else.
Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 07:04:44 von marss
On 17 СÑÑ, 05:08, "Lance Wynn" =
wrote:
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
>
>
If you use href=3D"/style.css" it refers to a stylesheet resided in the
root folder of an application
disregarding of position of the parent page in a website hierarchy.
IMHO, no need to convert the stylesheet link to a server control, a
leading slash "/" for HTML elements do the same as "~/" for web/HTML
controls.
Regards,
Mykola
http://marss.co.ua - Casual ideas for web development
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 08:22:46 von John
Just to add, if you're refering to Master pages then a Link tag within the
Head section gets resolved before being combined with its content page so
"style.css" should work in your case (also link tags within conditional
comments - thanks Steven). I've just read "ASP.Net 2.0 - Master Pages:
Tips, Tricks, and Traps" by K. Scott Allen
(http://odetocode.com/Articles/450.aspx) which is a great article on the
subject.
Hope that helps.
Best regards
John
"Lance Wynn" wrote in message
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
>
>
> Is this possible to do with the link element?
>
> Thanks
>
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 09:43:01 von Leon Mayne
"Lance Wynn" wrote in message
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
>
>
> Is this possible to do with the link element?
Adding runat="server" should do it:
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 10:44:22 von Hans Kesting
marss brought next idea :
> On 17 СÑÑ, 05:08, "Lance Wynn" wrote:
>> Hello all,
>> Is there a way to use the ~/ path to link a CSS page?
>>
>> I thought maybe something like this would work, but no go:
>>
>>
>
> If you use href="/style.css" it refers to a stylesheet resided in the
> root folder of an application
> disregarding of position of the parent page in a website hierarchy.
> IMHO, no need to convert the stylesheet link to a server control, a
> leading slash "/" for HTML elements do the same as "~/" for web/HTML
> controls.
>
> Regards,
> Mykola
> http://marss.co.ua - Casual ideas for web development
That will work for a production server where the root of the
application is http://www.company.com.
It will fail on your development box where you want to use
http://localhost/CompanyDevSite
The ~ syntax (when used correctly) will work in both cases.
Hans Kesting
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 12:01:01 von marss
On 17 СÑÑ, 11:44, Hans Kesting
m> wrote:
> It will fail on your development box where you want to usehttp://localhost=
/CompanyDevSite
You are right, I completely forgot this aspect.
Perhaps, I became too spoilt by VS 2005 using http://localhost:1720/
instead of http://localhost/MySite/ :)
Regards,
Mykola
http://marss.co.ua - Casual ideas of web development
Re: Using ~/ path for to link a CSS page?
am 17.01.2008 13:22:17 von Patrice
Another option is to place the stylesheet in the site theme folder. It will
be then automatically referenced from your pages...
--
Patrice
"Lance Wynn" a écrit dans le message de news:
OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
>
>
> Is this possible to do with the link element?
>
> Thanks
>